// ---------------------------------------------------- // // i2c_scanner plus read BMP180 Sensor using Adafruit Libraries // Version 1.0 // Version 1.0 October 10,2107 // by Microrustyc // I2C Scanning addresses from 0...127 // This sketch tests the standard 7-bit addresses // Devices with higher bit address might not be seen properly. // Baud rate 115200 for console Port // Reads BMP180 Altitude and Air Pressure and display to Console // // ----------------------------------------------------- #include // Include Arduino I2C library #include // Adafruit BMP085 Library Version 1.0.0 or Adafruti BMP085 Unified Version 1.0.0? Adafruit_BMP085 bmp; int bmp_ERR =0; void setup() { Serial.begin(115200); Serial.println("Oct 25, 2017 Embedded Workshop."); Serial.println("Baud rate 115200 for console Port."); Serial.println("Reads BMP180 Altitude and Air Pressure and display to Console"); Serial.println (); //Line Feed Wire.begin(); // Start I2C Serial.println("\nI2C Scanner"); // Print to console } void loop() { Scanner(); // Check for I2C devices connected Test_bmp(); // Check for the BMP Sensor Read_BMP180(); // Read the sensor } void Scanner() { byte error, address; int nDevices; Serial.println("Scanning..."); // Print to console nDevices = 0; //number of devices for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknow error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan return; } void Test_bmp() { if (!bmp.begin()) { Serial.println("Could not find BMP180 or BMP085 sensor at 0x77"); // Display Error Message to Console Serial.println(); delay(5000); // wait 5 seconds for next scan and wait for scan to clear bmp_ERR = 1; return; } return; } void Read_BMP180() { if (!bmp.begin()) { Serial.println("Could not find BMP180 or BMP085 sensor at 0x77"); // Display Error Message to Console Serial.println(); delay(8000); bmp_ERR = 1; return; } float inch; float mbar; float Alt; float Temp1; float Press; // Display to Console Port Serial.println("BMP Sensor Connected and Working "); Serial.println(); Serial.print("Temperature = "); Serial.print(bmp.readTemperature()); Serial.println(" °C"); Serial.print("Pressure = "); Serial.print(bmp.readPressure()); Serial.println(" Pa"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print("Altitude = "); Serial.print(bmp.readAltitude()); Serial.println(" meters"); Serial.print("Altitude = "); Alt = bmp.readAltitude(); Alt = Alt * 3.2808; Serial.print(Alt); Serial.println(" Feet"); Serial.print("Pressure at sea level (calculated) = "); Serial.print(bmp.readSealevelPressure()); Serial.println(" Pa"); // you can get a more precise measurement of altitude // if you know the current sea level pressure which will // vary with weather and such. If it is 1015 millibars // that is equal to 101500 Pascals. Serial.print("Real altitude = "); Serial.print(bmp.readAltitude(101500)); Serial.println(" meters"); Serial.println(); delay(5000); // wait 5 seconds for next scan and wait for scan to clear return; }